var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2WeChatConstant = require("WeChatConstant");
var $2ADManager = require("ADManager");
var $2BundleManager = require("BundleManager");
var $2ExcelManager = require("ExcelManager");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2MyUtils = require("MyUtils");
var $2MenuUI = require("MenuUI");
var $2RewardUI = require("RewardUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_TaskUI = /* */function (_cc$Component72) {
  babel_inherits(f, _cc$Component72);
  var _super88 = babel_createSuper(f);
  function f() {
    var _this210;
    babel_classCallCheck(this, f);
    _this210 = _super88.apply(this, arguments);
    _this210.taskList = null;
    _this210.extraLabel = null;
    _this210.extraBtn = null;
    _this210.taskInfo = [];
    return _this210;
  }
  babel_createClass(f, [{
    key: "onLoad",
    value: function onLoad() {
      this.init();
    }
  }, {
      key: "init",
      value: function init() {
        Adv_skd.default.instance.hideAllAdv();
        Adv_skd.default.instance.showInterstitialAd();
        Adv_skd.default.instance.showGridAdRight();
        Adv_skd.default.instance.showGridAdLeft();

        switch ($2ADManager.default.instance.sdkType) {
          case $2ADManager.SDK_TYPE.WeChat:
            $2ADManager.default.instance.showNative(2);
            $2ADManager.default.instance.showNative(3);
            $2ADManager.default.instance.showNative(1);
            $2ADManager.default.instance.hideNative(0);
            $2ADManager.default.instance.showBanner();
        }
      this.taskInfo = $2UserDataManager.default.instance.taskInfo;
      this.taskTable = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.taskTable);
      for (var _e124 = 1; _e124 <= this.taskList.childrenCount; _e124++) {
        var _t73 = undefined;
        this.taskList.children[_e124 - 1].getChildByName("Word").getComponent(cc.Label).string = this.taskTable[this.taskInfo[_e124].id].name;
        this.taskList.children[_e124 - 1].getChildByName("ProgressNum").getComponent(cc.Label).string = this.taskInfo[_e124].progress + "/" + this.taskTable[this.taskInfo[_e124].id].aim;
        (_t73 = this.taskInfo[_e124].progress / this.taskTable[this.taskInfo[_e124].id].aim) > 1 && (_t73 = 1);
        this.taskList.children[_e124 - 1].getChildByName("ProgressBar").getComponent(cc.ProgressBar).progress = _t73;
        if (_t73 < 1 || this.taskInfo[_e124].finish) {
          this.taskList.children[_e124 - 1].getChildByName("Btn").getComponent(cc.Button).interactable = false;
          this.taskInfo[_e124].finish && (this.taskList.children[_e124 - 1].getChildByName("Btn").getComponentInChildren(cc.Label).string = "已领取");
        } else {
          this.taskList.children[_e124 - 1].getChildByName("Btn").getComponent(cc.Button).interactable = true;
        }
        switch (this.taskInfo[_e124].type) {
          case "a":
            this.taskList.children[_e124 - 1].getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
            break;
          case "b":
            this.taskList.children[_e124 - 1].getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
            break;
          case "c":
            this.taskList.children[_e124 - 1].getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + this.taskInfo[_e124].plantID, cc.SpriteFrame);
        }
        this.taskList.children[_e124 - 1].getChildByName("Num").getComponent(cc.Label).string = this.taskTable[this.taskInfo[_e124].id].rewardNum;
      }
      this.extraLabel.string = "完成度: " + this.taskInfo[0].progress + "/" + this.taskTable[this.taskInfo[0].id].aim;
      if (this.taskInfo[0].progress >= this.taskTable[this.taskInfo[0].id].aim) {
        if (this.taskInfo[0].finish) {
          this.extraBtn.interactable = false;
          this.extraBtn.node.getComponentInChildren(cc.Label).string = "已领取";
        } else {
          this.extraBtn.interactable = true;
          this.extraBtn.node.getComponentInChildren(cc.Label).string = "领取";
        }
      } else {
        this.extraBtn.interactable = false;
        this.extraBtn.node.getComponentInChildren(cc.Label).string = "领取";
      }
    }
  }, {
    key: "onClickReward",
    value: function onClickReward(e, t) {
      var a = Number(t);
      var n = [];
      var i = {
        rewardType: undefined,
        rare: undefined,
        number: undefined,
        plantID: undefined
      };
      switch (this.taskInfo[a].type) {
        case "a":
          $2UserDataManager.default.instance.gold += this.taskTable[this.taskInfo[a].id].rewardNum;
          i.rare = 1;
          i.rewardType = "c";
          break;
        case "b":
          $2UserDataManager.default.instance.diamond += this.taskTable[this.taskInfo[a].id].rewardNum;
          i.rare = 2;
          i.rewardType = "c";
          break;
        case "c":
          $2UserDataManager.default.instance.setPlantChip(this.taskInfo[a].plantID, this.taskTable[this.taskInfo[a].id].rewardNum);
          i.rewardType = "a";
          i.plantID = this.taskInfo[a].plantID;
      }
      e.currentTarget.getComponent(cc.Button).interactable = false;
      e.currentTarget.getComponentInChildren(cc.Label).string = "已领取";
      if (0 !== a) {
        $2UserDataManager.default.instance.taskInfo[0].progress++;
        this.extraLabel.string = "完成度: " + this.taskInfo[0].progress + "/" + this.taskTable[this.taskInfo[0].id].aim;
      }
      $2UserDataManager.default.instance.taskInfo[a].finish = true;
      6 == $2UserDataManager.default.instance.taskInfo[0].progress && (this.extraBtn.interactable = true);
      if (0 === a) {
        this.extraBtn.interactable = false;
        $2UserDataManager.default.instance.taskInfo = $2UserDataManager.default.instance.taskInfo;
      }
      i.number = this.taskTable[this.taskInfo[a].id].rewardNum;
      n.push(i);
      $2UIManager.default.instance.openUI("RewardUI", 30).getComponent($2RewardUI.default).init(n);
    }
  }, {
    key: "onClickClose",
    value: function onClickClose() {
      Adv_skd.default.instance.hideAllAdv();

      $2UIManager.default.instance.closeUI("TaskUI");
      $2UIManager.default.instance.uiList.MenuUI.getComponent($2MenuUI.default).showNode();
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
        $2MyUtils.MyUtils.probability($2WeChatConstant.default.mainInster) && $2ADManager.default.instance.showInsert();
        $2ADManager.default.instance.hideNative(2);
        $2ADManager.default.instance.hideNative(3);
        $2ADManager.default.instance.showNative(0);
        $2ADManager.default.instance.hideNative(1);
      }
    }
  }]);
  return f;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_TaskUI.prototype, "taskList", undefined);
cc__decorate([ccp_property(cc.Label)], def_TaskUI.prototype, "extraLabel", undefined);
cc__decorate([ccp_property(cc.Button)], def_TaskUI.prototype, "extraBtn", undefined);
def_TaskUI = cc__decorate([ccp_ccclass], def_TaskUI);
exports.default = def_TaskUI;